<template xmlns:el-col="http://www.w3.org/1999/html">
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleTabClick">
      <el-tab-pane label="设备数据" name="0">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="选择设备" prop="equipmentCode">
            <el-select v-model="queryParams.equipmentCode" placeholder="请选择">
              <el-option
                v-for="dict in equipmentList"
                :key="dict.gyroscopeCode"
                :label="dict.equipmentName"
                :value="dict.gyroscopeCode"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="计算标题" prop="calculateTitle">
            <el-input
              v-model="queryParams.calculateTitle"
              placeholder="请输入计算标题"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['baseinfo:calculateTx:add']"
            >新增Tx计算</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['baseinfo:calculateTx:remove']"
            >删除</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="calculateTxList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <!--      <el-table-column label="主键" align="center" prop="id" />-->
          <el-table-column label="计算标题" align="center" prop="calculateTitle" />
          <el-table-column label="设备名称" align="center" prop="equipmentName" />
          <el-table-column label="深度" align="center" prop="degreeDepth" />
          <el-table-column label="数据开始时间" align="center" prop="startTime" width="180"/>
          <el-table-column label="数据结束时间" align="center" prop="endTime" width="180"/>
          <el-table-column label="导热系数K" align="center" prop="k" />
          <el-table-column label="地层导热系数λ" align="center" prop="lm" />
          <el-table-column label="计算点距离H" align="center" prop="h" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-search"
                @click="handleResult(scope.row)"
              >查看</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-download"
                @click="handleExport(scope.row)"
              >导出</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['baseinfo:calculateTx:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane label="导入数据" name="1">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="计算标题" prop="calculateTitle">
            <el-input
              v-model="queryParams.calculateTitle"
              placeholder="请输入计算标题"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleImport"
              v-hasPermi="['baseinfo:calculateTx:add']"
            >导入数据计算</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['baseinfo:calculateTx:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="importTemplate"
            >下载导入模板</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="calculateTxList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <!--      <el-table-column label="主键" align="center" prop="id" />-->
          <el-table-column label="计算标题" align="center" prop="calculateTitle" />
<!--          <el-table-column label="设备名称" align="center" prop="equipmentName" />-->
<!--          <el-table-column label="深度" align="center" prop="degreeDepth" />-->
<!--          <el-table-column label="数据开始时间" align="center" prop="startTime" width="180"/>-->
<!--          <el-table-column label="数据结束时间" align="center" prop="endTime" width="180"/>-->
<!--          <el-table-column label="导热系数K" align="center" prop="k" />-->
<!--          <el-table-column label="地层导热系数λ" align="center" prop="lm" />-->
<!--          <el-table-column label="计算点距离H" align="center" prop="h" />-->
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-search"
                @click="handleExcelResult(scope.row)"
              >查看</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-download"
                @click="handleExport(scope.row)"
              >导出</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['baseinfo:calculateTx:remove']"
              >删除</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
              >计算</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
    </el-tabs>


    <!-- 添加或修改Tx计算记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="选择设备" prop="equipmentCode">
              <el-select v-model="form.equipmentCode"  placeholder="请选择">
                <el-option
                  v-for="dict in equipmentList"
                  :key="dict.gyroscopeCode"
                  :label="dict.equipmentName"
                  :value="dict.gyroscopeCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="数据时间" prop="dataTime">
              <el-date-picker
                v-model="dateRange"
                size="small"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetimerange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="数据条数">
              {{total1}}
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item style="float: right">
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleChartQuery">搜索</el-button>
            </el-form-item>
          </el-col>

          <el-col>
            <line-chart-four key="chat1" v-if="total1>0" :chart-data="chartData" :check-list ="checkList" :legend-show="true"></line-chart-four>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">计算参数选择</el-divider>
          </el-col>
          <el-col :span="24">
            <el-form-item label="选择深度">
              <el-checkbox-group v-model="checkList">
                <el-checkbox label="5m"  key="5">温度5m</el-checkbox>
                <el-checkbox label="10m" key="10">温度10m</el-checkbox>
                <el-checkbox label="15m" key="15">温度15m</el-checkbox>
                <el-checkbox label="20m" key="20">温度20m</el-checkbox>
                <el-checkbox label="25m" key="25">温度25m</el-checkbox>
                <el-checkbox label="30m" key="30">温度30m</el-checkbox>
                <el-checkbox label="35m" key="35">温度35m</el-checkbox>
                <el-checkbox label="40m" key="40">温度40m</el-checkbox>
                <el-checkbox label="45m" key="45">温度45m</el-checkbox>
                <el-checkbox label="50m" key="50">温度50m</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计算标题" prop="calculateTitle">
              <el-input v-model="form.calculateTitle" placeholder="请输入计算标题" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="导热系数K" prop="k">
              <el-input v-model="form.k" placeholder="请输入导热系数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计算点高度H" prop="h">
              <el-input v-model="form.h" placeholder="请输入高度值" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地层导热系数λ" prop="lm">
              <el-input v-model="form.lm" placeholder="请输入地层导热系数" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleCalculation">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="计算结果" :visible.sync="resultOpen" width="800px" append-to-body>
      <el-form ref="form" :model="form"  label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-divider content-position="left">计算参数</el-divider>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备名称">
              <span>{{form.equipmentName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计算标题">
              <span>{{form.calculateTitle}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="深度">
              <span>{{form.degreeDepth}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="导热系数K">
              <span>{{form.k}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计算点高度H">
              <span>{{form.h}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="地层导热系数λ">
              <span>{{form.lm}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="数据时间" >
              <span>{{form.startTime +"--"+ form.endTime}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="创建人" >
              <span>{{form.createBy}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">计算数据及结果</el-divider>
          </el-col>
          <el-col :span="24">
            <line-chart-four1 v-if="chart2 && Object.keys(chartData).length>0" :chart-data="chartData"  :legend-show="true"></line-chart-four1>
          </el-col>
<!--          <el-col :span="24">
            <el-divider content-position="left">计算结果Tx</el-divider>
          </el-col>
          <el-col :span="24">
            <line-chart-four v-if="Object.keys(resultChartData).length>0" :chart-data="resultChartData" :check-list ="checkList"></line-chart-four>
          </el-col>-->

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="导入Excel计算结果" :visible.sync="resultExcelOpen" width="800px" append-to-body>
      <el-form ref="form" :model="form"  label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-divider content-position="left">计算参数</el-divider>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计算标题">
              <span>{{form.calculateTitle}}</span>
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item label="深度">-->
<!--              <span>{{form.degreeDepth}}</span>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="6">-->
<!--            <el-form-item label="导热系数K">-->
<!--              <span>{{form.k}}</span>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="6">-->
<!--            <el-form-item label="计算点高度H">-->
<!--              <span>{{form.h}}</span>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="6">-->
<!--            <el-form-item label="地层导热系数λ">-->
<!--              <span>{{form.lm}}</span>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="6">
            <el-form-item label="创建人" >
              <span>{{form.createBy}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">计算数据及结果</el-divider>
          </el-col>
          <el-col>
            <line-chart-six key="chat4" v-if="Object.keys(chartData4).length>0" :chart-data="chartData4" :height="height" :width="width"  :legend-show="true"></line-chart-six>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelExcelShow">关 闭</el-button>
      </div>
    </el-dialog>








    <!-- 添加或修改Tx计算值对话框 -->
    <el-dialog :title="ComputeTxtitle" :visible.sync="ComputeTxOpen" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="选择文件" >
                  <el-upload
                    ref="upload"
                    class="upload"
                    :limit="1"
                    accept=".xlsx, .xls"
                    :headers="upload.headers"
                    :action="upload.url + '?updateSupport=' + upload.updateSupport"
                    :disabled="upload.isUploading"
                    :auto-upload="true"
                    :show-file-list="true"
                    :on-success="handleFileSuccess"
                    drag
                  >
                    <i class="el-icon-upload"></i>
                    <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                    <div class="el-upload__tip text-center" slot="tip">
                    </div>
                  </el-upload>
            </el-form-item>

          </el-col>
          <el-col>
            <line-chart-five key="chat2" v-if="Object.keys(chartData2).length>0" :chart-data="chartData2"  :height="height" :width="width" :legend-show="true"></line-chart-five>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计算标题" prop="calculateTitle">
              <el-input v-model="form.calculateTitle" placeholder="请输入计算标题" />
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item label="T1深度(米)" prop="deepOne">-->
<!--              <el-input v-model="form.deepOne" placeholder="请输入T1深度数值" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="T2深度(米)" prop="deepTwo">-->
<!--              <el-input v-model="form.deepTwo" placeholder="请输入T2深度数值" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--            <el-col :span="12">-->
<!--              <el-form-item label="导热系数K" prop="k">-->
<!--                <el-input v-model="form.k" placeholder="请输入导热系数" />-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :span="12">-->
<!--              <el-form-item label="计算点高度H" prop="h">-->
<!--                <el-input v-model="form.h" placeholder="请输入高度值" />-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :span="12">-->
<!--              <el-form-item label="地层导热系数λ" prop="lm">-->
<!--                <el-input v-model="form.lm" placeholder="请输入地层导热系数" />-->
<!--              </el-form-item>-->
<!--            </el-col>-->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTxForm">计 算</el-button>
        <el-button @click="cancelTx">关 闭</el-button>
      </div>
    </el-dialog>



    <!-- 添加或修改Tx计算值对话框 -->
    <el-dialog :title="UpdateComputeTxtitle" :visible.sync="UpdateComputeTxOpen" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col>
            <line-chart-six key="chat3" v-if="Object.keys(chartData3).length>0" :chart-data="chartData3" :height="height" :width="width" :legend-show="true"></line-chart-six>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计算标题" prop="calculateTitle">
              <el-input v-model="form.calculateTitle" placeholder="请输入计算标题" />
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item label="T1深度(米)" prop="deepOne">-->
<!--              <el-input v-model="form.deepOne" placeholder="请输入T1深度(数字)" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="T2深度(米)" prop="deepTwo">-->
<!--              <el-input v-model="form.deepTwo" placeholder="请输入T2深度(数字)" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="导热系数K" prop="k">-->
<!--              <el-input v-model="form.k" placeholder="请输入导热系数" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="计算点高度H" prop="h">-->
<!--              <el-input v-model="form.h" placeholder="请输入高度值" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="地层导热系数λ" prop="lm">-->
<!--              <el-input v-model="form.lm" placeholder="请输入地层导热系数" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitUpdateTxForm">计 算</el-button>
        <el-button @click="cancelUpdateTx">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listCalculateTx, getCalculateTx, delCalculateTx, addCalculateTx, updateCalculateTx,addExcelCalculateTx } from "@/api/baseinfo/calculateTx";
import {getEquipments} from "@/api/baseinfo/equipment";
import {getTemperatureChartData} from "@/api/baseinfo/moreTemperatureData";
import LineChartFour from "@/views/LineChart/LineChartFour.vue";
import LineChartFour1 from "@/views/LineChart/LineChartFour.vue";
import {getToken} from "@/utils/auth";
import LineChartFive from "@/views/LineChart/LineChartFive";
import LineChartOne from "@/views/LineChart/LineChartOne";
import LineChartSix from "@/views/LineChart/LineChartSix";

export default {
  name: "CalculateTx",
  components: {
    LineChartSix,
    LineChartOne,
    LineChartFour,
    LineChartFour1,
    LineChartFive
  },
  data() {
    return {
      activeName:0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1:0,
      chart2:false,
      // Tx计算记录表格数据
      calculateTxList: [],
      //多点测温设备列表
      equipmentList: [],
      chartData: {},
      chartData2: {},
      chartData3: {},
      chartData4: {},
      resultChartData:{},
      checkList:[],
      dateRange:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      resultOpen: false,
      //Tx计算
      ComputeTxOpen:false,
      ComputeTxtitle:"",
      //修改Tx计算
      UpdateComputeTxtitle:'',
      UpdateComputeTxOpen:false,
      height:'300px',
      width:'760px',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equipmentCode: null,
        calculateTitle: null,
        degreeDepth: null,
        startTime: null,
        endTime: null,
        k: null,
        lm: null,
        h: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        equipmentCode: [
          { required: true, message: "请选择设备", trigger: "change" }
        ],
        calculateTitle:[
          { required: true, message: "请填写计算标题", trigger: "blur" }
        ],
        k:[
          { required: true, message: "请填写导热系数K", trigger: "blur" }
        ],
        lm:[
          { required: true, message: "请输入地层导热系数λ", trigger: "blur" }
        ],
        h:[
          { required: true, message: "请填写计算点高度H", trigger: "blur" }
        ],
        deepOne:[
          { required: true, message: "请填写T1深度", trigger: "blur" }
        ],
        deepTwo:[
          { required: true, message: "请填写T2深度", trigger: "blur" }
        ]
      },
      // 用户导入参数
      upload: {
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/baseinfo/calculateTx/importData",
        // 是否更新已经存在的用户数据
        updateSupport: 0,
      },
      resultExcelOpen:false
    };
  },
  created() {
    this.getEquipmentList();
    this.getList();
  },
  methods: {
    handleTabClick(){
      this.getList()
    },
    /** 查询Tx计算记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.calcType = this.activeName;
      listCalculateTx(this.queryParams).then(response => {
        this.calculateTxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //多点测温设备列表
    getEquipmentList() {
      getEquipments({equipmentType:"2"}).then(response => {
        this.equipmentList = response.data;
      });
    },
    handleChartQuery() {
      this.handleTemperatureChartData();
    },
    handleTemperatureChartData(){
      getTemperatureChartData(this.addDateRange(this.form, this.dateRange)).then(res =>{
        this.chartData = res.chartData;
        this.total1 = res.total;
        this.$modal.msgSuccess("查询成功");
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.resultOpen = false;
      this.reset();
    },
    //关掉导入Tx的计算
    cancelTx(){
      this.ComputeTxOpen=false;
      this.reset();
    },
    //关掉Tx的计算
    cancelUpdateTx(){
      this.UpdateComputeTxOpen=false;
      this.reset();
    },
    //关掉查看Excel结果
    cancelExcelShow(){
      this.resultExcelOpen=false;
      this.reset();
    },
    //更新按钮
    handleUpdate(row){
      this.UpdateComputeTxOpen = true;
      this.UpdateComputeTxtitle = "Tx计算";
      const id = row.id || this.ids
      getCalculateTx(id).then(response => {
        this.form=response.data;
        let chart={
          t1:null,
          t2:null,
          tx:null
        };
        let t1 = [];
        let t2 = [];
        let tx = [];
        this.form.txValueList.forEach(item => {
          t1.push(item.t1);
          t2.push(item.t2);
          tx.push(item.tx);
        })
        chart.t1=t1;
        chart.t2=t2;
        chart.tx=tx;
        this.chartData3=chart;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        equipmentCode: null,
        calculateTitle: null,
        degreeDepth: null,
        startTime: null,
        endTime: null,
        k:1.0,
        h:1.0,
        lm: 2.9,
        createBy: null,
        createTime: null,
        deepOne:null,
        deepTwo:null
      };
      this.checkList = [];
      this.chart2 = false;
      this.total1 = 0;
      this.dateRange =[];
      this.chartData = {};
      this.resultChartData = {}
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 导入excel */
    handleImport(){
      //todo
      this.reset();
      this.ComputeTxOpen = true;
      this.ComputeTxtitle = "添加Tx计算记录";
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      if(response.code == 200){
        this.form = response.data
        this.chartData2 = response.data.tempDataList.chartData;
        console.log('得到响应',response.data)
        this.$modal.msgSuccess("生成数据成功");
        this.getList();
      }else {
        this.$modal.msgError("文件导入失败,请检查文件数据格式是否正确!")
      }
      this.$refs.upload.clearFiles();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加Tx计算记录";
    },
    /** 查看数据结果 */
    handleResult(row) {
      console.log("----------查看")
      this.reset();
      const id = row.id || this.ids
      getCalculateTx(id).then(response => {
        this.form = response.data;
        let t1 = [];
        let t2 = [];
        let tx = [];
        let time = []
        this.form.txValueList.forEach(item => {
          t1.push(item.t1);
          t2.push(item.t2);
          tx.push(item.tx);
          time.push(item.dataTime)
        })
        let degreeDepth = this.form.degreeDepth.split('-')
        let chartData = {}
        chartData[degreeDepth[0]]=t1;
        chartData[degreeDepth[1]]=t2;
        chartData['Tx']=tx;

        let chart = {};
        chart["temperatureData"] = chartData;
        chart["timeList"] = time;
        this.chartData = chart;
        /*this.chartData["temperatureData"] = chartData;
        this.chartData["timeList"] = time;*/
        /*this.resultChartData["temperatureData"]= {Tx :tx};
        this.resultChartData["timeList"]= time;*/
        /*this.$set(this.chartData,'temperatureData',chartData)
        this.$set(this.chartData,'timeList',time)*/
        this.chart2 = true
        console.log(this.chartData)
        this.resultOpen = true;
      });
    },
    /**
     * 查看导入Excel导入结果
     */
    handleExcelResult(row){
      this.reset();
      const id = row.id || this.ids
      getCalculateTx(id).then(response => {
        this.form = response.data;
        let chart={
          t1:null,
          t2:null,
          tx:null
        };
        let t1 = [];
        let t2 = [];
        let tx = [];
        this.form.txValueList.forEach(item => {
          t1.push(item.t1);
          t2.push(item.t2);
          tx.push(item.tx);
        })
        chart.t1=t1;
        chart.t2=t2;
        chart.tx=tx;
        this.chartData4=chart;
      })
      this.resultExcelOpen = true;
    },
    //计算tx
    handleCalculation(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.checkList = this.checkList;
          if(this.form.checkList.length!=2){
            this.$modal.msgError("请选择2个探测点");
            return;
          }
          if(this.total1 == 0){
            this.$modal.msgError("当前无计算数据！");
            return;
          }
          addCalculateTx(this.addDateRange(this.form,this.dateRange)).then(res =>{
            this.open = false;
            this.getList();
            this.$modal.msgSuccess("计算完成");
          })
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCalculateTx(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCalculateTx(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    submitTxForm(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          addExcelCalculateTx(this.form).then(res =>{
            this.ComputeTxOpen = false;
            this.getList();
            this.$modal.msgSuccess("计算完成");
          })
        }
      });
    },
    //计算Tx
    submitUpdateTxForm(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          addExcelCalculateTx(this.form).then(res =>{
            this.UpdateComputeTxOpen = false;
            this.getList();
            this.$modal.msgSuccess("计算完成");
          })
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除Tx计算记录编号为"' + ids + '"的数据项？').then(function() {
        return delCalculateTx(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport(row) {
      let param = {calculateId: row.id}
      this.download('baseinfo/calculateTxValue/export', {
        ...param
      }, `${row.calculateTitle}.xlsx`)
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('baseinfo/calculateTxValue/importTemplate', {
      }, `Tx温度数据_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>

<style >
.upload .el-upload-dragger{
  width: 640px!important;
}
</style>
